package com.dfbz.filter;

import com.alibaba.druid.support.http.WebStatFilter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginFilter implements Filter {

    public void init(FilterConfig config) throws ServletException {

    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
   /*     HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        HttpSession session = req.getSession();
        Object loginUser = session.getAttribute("loginUser");
//      会话存在
        if (loginUser!=null){

            Cookie[] cookies = req.getCookies();
            for (Cookie cookie : cookies) {

                if (cookie.getName().equals("userInfo")) {
//                    req.getRequestDispatcher(req.getContextPath()+"/home").forward(req,resp);
                    resp.sendRedirect(req.getContextPath()+"/home");
                    return;
                }
            }
        }*/
        chain.doFilter(request, response);
    }

    public void destroy() {

    }


}
